package com.baomidou.springboot.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springboot.entity.Environment;
import com.baomidou.springboot.entity.Quality;
import com.baomidou.springboot.mapper.EnvironmentMapper;
import com.baomidou.springboot.service.EnvironmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 环境体系管理 服务实现类
 * </p>
 *
 * @author QQQ
 * @since 2018-06-19
 */
@Service
public class EnvironmentServiceImpl implements EnvironmentService {

    @Autowired
    private EnvironmentMapper environmentMapper;

    @Override
    public void save(Environment environment) {
        environment.setCreateDate(new Date());
        environmentMapper.insert(environment);
    }

    @Override
    public void delete(String id) {
        environmentMapper.deleteById(id);
    }

    @Override
    public Environment edit(String id) {
        return environmentMapper.selectById(id);
    }

    @Override
    public void update(Environment environment) {
        environment.setModifyDate(new Date());
        environmentMapper.updateById(environment);
    }

    @Override
    public Environment view(String id) {
        return environmentMapper.selectById(id);
    }

    @Override
    public Page<Environment> list(Page<Environment> page, String search) {
        if (0 == page.getSize()) {
            page.setSize(10);
        }
        if (0 == page.getCurrent()) {
            page.setCurrent(1);
        }
        List<Environment> environmentList = environmentMapper.findByDateDesc(page, search);
        page.setRecords(environmentList);
        return page;
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (null == ids) {
            return;
        }
        environmentMapper.deleteBatchIds(ids);
    }

    @Override
    public Environment findById(String id) {
        return environmentMapper.selectById(id);
    }

    @Override
    public List<Environment> findBySort() {
        return environmentMapper.findBySort();
    }
}
